﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
//using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace TRicheControl.DefaultControlStyles.Helper
{
    public class DrawHelper
    {
        public static void SetGraphics(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;  //使绘图质量最高，即消除锯齿
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = CompositingQuality.HighQuality;
        }

        public static void DrawCornerBoxBorder(Graphics g, Rectangle rect, Pen brodrPen, int cornerRadius)
        {
            //rect.Height -= cornerRadius;
            //rect.Width -= cornerRadius;
            g.DrawPath(brodrPen, CreateRoundedRectanglePath(rect, cornerRadius));
        }

        public static void FillCornerBox(Graphics g, Rectangle rect, Brush backGroundBrush, int cornerRadius)
        {
            rect.Height -= cornerRadius;
            rect.Width -= cornerRadius;
            g.FillPath(backGroundBrush, CreateRoundedRectanglePath(rect, cornerRadius));
        }

        /// <summary>
        /// 画正三角形
        /// </summary>
        public static void DrawTriangle(Graphics g, Rectangle rect, Color broderColor, int tilt)
        { 

        }

        private static GraphicsPath CreateTriangle(Rectangle rect, int tilt)
        {
            GraphicsPath trianglePath = new GraphicsPath();
            Point pA = new Point(rect.Width / 2, 0);
            Point pB = new Point(0, rect.Height);
            Point pC = new Point(rect.Width, rect.Height);
            trianglePath.AddLine(pA, pB);
            trianglePath.AddLine(pB, pC);
            trianglePath.AddLine(pC, pA);
            return trianglePath;
        }

        private static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
        {
            GraphicsPath roundedRect = new GraphicsPath();
            roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
            roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
            roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
            roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
            roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
            roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
            roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
            roundedRect.CloseFigure();
            return roundedRect;
        }
    }
}
